import java.util.StringTokenizer;

public class IType
{
	public static void convert(String line, int lineNumber, Assembled assembled)
	{
		StringTokenizer tokenizer = new StringTokenizer(line, " ,\t");
		String value = tokenizer.nextToken();
		int temp;
		int[] build = new int[6];
		int immediate;
		int[] templarge = new int[2];

		temp = itable(value);
		templarge[1] = Memory.memory(tokenizer.nextToken());
		templarge[0] = Memory.memory(tokenizer.nextToken());
		immediate = Integer.parseInt(tokenizer.nextToken());
		//immediate = toImmediate(tokenizer.nextToken());
		
		if((templarge[0] == templarge[1]) && templarge[0] == 29)
			immediate = immediate/4;
		
		build[0] = 1;
		build[1] = temp;
		build[2] = templarge[0];
		build[3] = templarge[1];
		build[4] = immediate;
		build[5] = lineNumber;
		
		assembled.addLine(build);
	}
//	generates the value for an immediate command
	public static int itable(String command)
	{
		if(command.equals("addi"))
			return 8; //"001000";
		if(command.equals("addiu"))
			return 9; //"001001";
		if(command.equals("andi"))
			return 12; //"001100";
		if(command.equals("ori"))
			return 13; //"001101";
		if(command.equals("slti"))
			return 10; //"001010";
		if(command.equals("sltiu"))
			return 11; //"001011";
		if(command.equals("xori"))
			return 14; //"001110";
		return -1;
	}

	public static int[] li(String line, int lineNumber)
	{
		StringTokenizer tokenizer = new StringTokenizer(line, " ,\t");
		int[] build = new int[6];//new String("15");//("001111");
		tokenizer.nextToken();//String dump = 
		
		build[0] = 1;
		build[1] = 15;
		build[2] = 0;
		build[3] = Memory.memory(tokenizer.nextToken());
		build[4] = Integer.parseInt(tokenizer.nextToken());
		build[5] = lineNumber;
		
		return build;
	}
	
	public static void liconvert(String line, int lineNumber, Assembled assembled)
	{
		StringTokenizer tokenizer = new StringTokenizer(line, " ,\t");
		int[] build = new int[6];//new String("15");//("001111");
		tokenizer.nextToken();//String dump = 
		
		build[0] = 1;
		build[1] = 15;
		build[2] = 0;
		build[3] = Memory.memory(tokenizer.nextToken());
		build[4] = Integer.parseInt(tokenizer.nextToken());
		build[5] = lineNumber;
		
		assembled.addLine(build);
	}
/*	
	//generates the value that is output for immediate commands
	public static String icommand(String input)
	{
		StringTokenizer tokenizer = new StringTokenizer(input, " ,\t");
		String value = tokenizer.nextToken();
		String temp = new String();
		String build = new String();
		String immediate;
		String[] templarge = new String[2];

		temp = itable(value);
		templarge[1] = memory(tokenizer.nextToken());
		templarge[0] = memory(tokenizer.nextToken());
		immediate = tokenizer.nextToken();
		//immediate = toImmediate(tokenizer.nextToken());
		
		if(templarge[0].equals(templarge[1]) && templarge[0].equals("29"))
			immediate = "" + (Integer.parseInt(immediate)/4);
		
		build = temp + " " + templarge[0] + " " + templarge[1] + " " + immediate;
		
		return build;
	}
*/
}